package com.ck.daoImpl;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.ck.dao.ExamDAO;
import com.ck.domain.Exam;

public class ExamDAOImpl extends SqlMapClientDaoSupport implements ExamDAO {

	public List<Exam> getAllUnstartExam() {
		return (List<Exam>)getSqlMapClientTemplate().queryForList("getAllUnstartExam");
	}
	
	public List<Exam> getAllOnGoingExam() {
		return (List<Exam>)getSqlMapClientTemplate().queryForList("getAllOnGoingExam");
	}
	
	public List<Exam> getAllFinishedExam() {
		return (List<Exam>)getSqlMapClientTemplate().queryForList("getAllFinishedExam");
	}
	
	public Exam getExamById(Integer id) {
		return (Exam) getSqlMapClientTemplate().queryForObject("getExamById",id);
	}

	public Exam getExamByTitle(String title) {
		return (Exam) getSqlMapClientTemplate().queryForObject("getExamByTitle",title);
	}
	
	public Exam getUnstartExamById(Integer id) {
		return (Exam) getSqlMapClientTemplate().queryForObject("getUnstartExamById",id);
	}

	public void addNewExam(Exam exam) {
		getSqlMapClientTemplate().insert("addNewExam", exam);
	}

	public void updateUnstartExamInfo(Exam exam) {
		getSqlMapClientTemplate().update("updateUnstartExamInfo", exam);
	}

	public void updatePaperForExam(Integer examID, Integer paperID) {
		Exam exam = new Exam();
		exam.setId(examID);
		exam.setPaper(paperID);
		
		getSqlMapClientTemplate().update("updatePaperForExam", exam);
	}

}
